package com.wicket.okrdataassets.biz.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.wicket.okrcomponent.integration.FwCompInterfaceModeClient;
import com.wicket.okrcomponent.integration.dto.*;
import com.wicket.okrdataassets.biz.service.dto.req.*;
import com.wicket.okrdataassets.biz.service.dto.res.*;
import com.wicket.okrdataassets.common.exception.BizException;
import com.wicket.okrdataassets.common.util.CommonFunctionHelper;
import com.wicket.okrdataassets.common.util.RedisUtil;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import cn.hutool.core.collection.CollectionUtil;
import com.wicket.okrdataassets.common.exception.Assert;
import com.wicket.okrcomponent.integration.FwCompResourceFileClient;
import com.wicket.okrcomponent.integration.FwCompIntelligentCommunicationClient;
import com.wicket.okrdataassets.biz.service.ResourceFileService;

/**
 * @author ：
 * @date ：
 *
 *
 * @version 1.0
 */
@Service
public class IntelligentCommunicationServiceImpl
  implements com.wicket.okrdataassets.biz.service.IntelligentCommunicationService {

  @Resource
  private RedisUtil redisUtil;
@Resource
  private FwCompResourceFileClient fwCompResourceFileClient;
@Resource
  private FwCompIntelligentCommunicationClient fwCompIntelligentCommunicationClient;
@Resource
private FwCompInterfaceModeClient fwCompInterfaceModeClient;
@Resource
  private ResourceFileService resourceFileService;
/**
   * D8执行单个文件长文本问答[10429]
   * gen by moon at 12/15/2024, 5:14:01 PM
   */
  @Trace(operationName = "D8执行单个文件长文本问答")
  @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Transactional(rollbackFor=Exception.class)
  @Override
  public ImplementFileQaRespDto implementFileQa(ImplementFileQaReqDto reqDto){
    
      
      ImplementGuidedThirdPartyIntelligentQaComRespDto implementGuidedThirdPartyIntelligentQaComRespDto_1 =null;
//步骤0: D2执行上传文件到第三方智能问答(公共) - implementUploadFileToThirdQaCom
     ImplementUploadFileToThirdQaComRespDto implementUploadFileToThirdQaComRespDto = null;
    ImplementUploadFileToThirdQaComReqDto implementUploadFileToThirdQaComReqDto=new ImplementUploadFileToThirdQaComReqDto();
  if(reqDto!=null){
      implementUploadFileToThirdQaComReqDto.setResourceFileRelaPath(reqDto.getResourceFileRelaPath());//SimpleFieldAssign//sourceId:2034167_1
    }
  
    /*D2执行上传文件到第三方智能问答(公共)[10424]   */
    Assert.isNull(implementUploadFileToThirdQaComReqDto.getResourceFileRelaPath(),"D8执行单个文件长文本问答-D2执行上传文件到第三方智能问答(公共)-资源文件相对路径不能为空",false);
      implementUploadFileToThirdQaComRespDto = fwCompIntelligentCommunicationClient.implementUploadFileToThirdQaCom(implementUploadFileToThirdQaComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;
      
      
      
    
//步骤1: D2生成单个文件长文本问答(公共) - generateFileQaCom
     GenerateFileQaComRespDto generateFileQaComRespDto = null;
    if(implementUploadFileToThirdQaComRespDto !=null){
          GenerateFileQaComReqDto generateFileQaComReqDto=new GenerateFileQaComReqDto();
  if(implementUploadFileToThirdQaComRespDto!=null){
      generateFileQaComReqDto.setLongTextFileId(implementUploadFileToThirdQaComRespDto.getThirtPartFileId());//SimpleFieldAssign//sourceId:2036985_1
    }
  
    /*D2生成单个文件长文本问答(公共)[10426]   */
    Assert.isNull(generateFileQaComReqDto.getLongTextFileId(),"D8执行单个文件长文本问答-D2生成单个文件长文本问答(公共)-长文本文件ID不能为空",false);
      generateFileQaComRespDto = fwCompIntelligentCommunicationClient.generateFileQaCom(generateFileQaComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;
      

      
           }

//步骤2: D2执行导向第三方智能问答(公共) - implementGuidedThirdPartyIntelligentQaCom
     ImplementGuidedThirdPartyIntelligentQaComRespDto implementGuidedThirdPartyIntelligentQaComRespDto = null;
    if(generateFileQaComRespDto !=null){
          ImplementGuidedThirdPartyIntelligentQaComReqDto implementGuidedThirdPartyIntelligentQaComReqDto=new ImplementGuidedThirdPartyIntelligentQaComReqDto();
  implementGuidedThirdPartyIntelligentQaComReqDto.setResultAspObjId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID//sourceId:2034170_1
implementGuidedThirdPartyIntelligentQaComReqDto.setBusModelVersion("LONG_TEXT_VERSION");//sourceId:2036981_1
if(generateFileQaComRespDto!= null&&  generateFileQaComRespDto.getGetListIntelligentAnswersList() !=null&& !CollectionUtil.isEmpty(generateFileQaComRespDto.getGetListIntelligentAnswersList())){
      implementGuidedThirdPartyIntelligentQaComReqDto.setGetListIntelligentAnswersList(generateFileQaComRespDto.getGetListIntelligentAnswersList().stream().map(item -> BeanUtil.toBean(item, GetListIntelligentAnswersDto.class)).collect(Collectors.toList()));//objList-to-objLists//sourceId:2034171_1
    }
  
    /*D2执行导向第三方智能问答(公共)[8103]   */
    Assert.isNull(implementGuidedThirdPartyIntelligentQaComReqDto.getResultAspObjId(),"D8执行单个文件长文本问答-D2执行导向第三方智能问答(公共)-开通对象ID不能为空",false);
Assert.isNull(implementGuidedThirdPartyIntelligentQaComReqDto.getBusModelVersion(),"D8执行单个文件长文本问答-D2执行导向第三方智能问答(公共)-业务模型版本不能为空",false);
      implementGuidedThirdPartyIntelligentQaComRespDto = fwCompIntelligentCommunicationClient.implementGuidedThirdPartyIntelligentQaCom(implementGuidedThirdPartyIntelligentQaComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;
      
      
      implementGuidedThirdPartyIntelligentQaComRespDto_1 = implementGuidedThirdPartyIntelligentQaComRespDto;
           }

//步骤3: D2-执行markdown转文本(公共) - implementMarkdownTurnToTextCom
     ImplementMarkdownTurnToTextComRespDto implementMarkdownTurnToTextComRespDto = null;
    if(implementGuidedThirdPartyIntelligentQaComRespDto !=null){
          ImplementMarkdownTurnToTextComReqDto implementMarkdownTurnToTextComReqDto=new ImplementMarkdownTurnToTextComReqDto();
  if(implementGuidedThirdPartyIntelligentQaComRespDto!=null){
      implementMarkdownTurnToTextComReqDto.setMarkdownContent(implementGuidedThirdPartyIntelligentQaComRespDto.getContent());//SimpleFieldAssign//sourceId:2037011_1
    }

    /*D2-执行markdown转文本(公共)[7517]   */
    
      implementMarkdownTurnToTextComRespDto = fwCompInterfaceModeClient.implementMarkdownTurnToTextCom(implementMarkdownTurnToTextComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;



           }

//步骤4: D8修改资源文件(公共) - updateResourceFileCom
     UpdateResourceFileComRespDto updateResourceFileComRespDto = null;
    if(implementMarkdownTurnToTextComRespDto !=null){
          UpdateResourceFileComReqDto updateResourceFileComReqDto=new UpdateResourceFileComReqDto();
  if(reqDto!=null){
      updateResourceFileComReqDto.setResourceFileId(reqDto.getResourceFileId());//SimpleFieldAssign//sourceId:2034178_1
    }
if(implementMarkdownTurnToTextComRespDto!=null){
      updateResourceFileComReqDto.setResourceFileSummary(implementMarkdownTurnToTextComRespDto.getCustomText());//SimpleFieldAssign//sourceId:2034174_1
    }
  
    /*D8修改资源文件(公共)[10317]   */
    Assert.isNull(updateResourceFileComReqDto.getResourceFileId(),"D8执行单个文件长文本问答-D8修改资源文件(公共)-资源文件ID不能为空",false);
Assert.isNull(updateResourceFileComReqDto.getResourceFileSummary(),"D8执行单个文件长文本问答-D8修改资源文件(公共)-资源文件简介不能为空",false);
      updateResourceFileComRespDto = resourceFileService.updateResourceFileCom(updateResourceFileComReqDto)/*vcase invoke isSameApp*/;
      
      
      
           }
    
ImplementFileQaRespDto retData = new ImplementFileQaRespDto();
  if(implementGuidedThirdPartyIntelligentQaComRespDto_1!=null){
      retData.setContent(implementGuidedThirdPartyIntelligentQaComRespDto_1.getContent());//SimpleFieldAssign//sourceId:2034916_1
    }
  

  
  
return retData;
  }
/**
   * D8执行单个文件长文本问答(公共)[10429]
   * gen by moon at 12/17/2024, 7:23:02 PM
   */
  @Trace(operationName = "D8执行单个文件长文本问答(公共)")
  @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Transactional(rollbackFor=Exception.class)
  @Override
  public ImplementFileQaComRespDto implementFileQaCom(ImplementFileQaComReqDto reqDto){


      ImplementGuidedThirdPartyIntelligentQaComRespDto implementGuidedThirdPartyIntelligentQaComRespDto_1 =null;
//步骤0: D2执行上传文件到第三方智能问答(公共) - implementUploadFileToThirdQaCom
     ImplementUploadFileToThirdQaComRespDto implementUploadFileToThirdQaComRespDto = null;
    ImplementUploadFileToThirdQaComReqDto implementUploadFileToThirdQaComReqDto=new ImplementUploadFileToThirdQaComReqDto();
  if(reqDto!=null){
      implementUploadFileToThirdQaComReqDto.setResourceFileRelaPath(reqDto.getResourceFileRelaPath());//SimpleFieldAssign//sourceId:2034167_1
    }

    /*D2执行上传文件到第三方智能问答(公共)[10424]   */
    Assert.isNull(implementUploadFileToThirdQaComReqDto.getResourceFileRelaPath(),"D8执行单个文件长文本问答(公共)-D2执行上传文件到第三方智能问答(公共)-资源文件相对路径不能为空",false);
      implementUploadFileToThirdQaComRespDto = fwCompIntelligentCommunicationClient.implementUploadFileToThirdQaCom(implementUploadFileToThirdQaComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;




//步骤1: D2生成单个文件长文本问答(公共) - generateFileQaCom
     GenerateFileQaComRespDto generateFileQaComRespDto = null;
    if(implementUploadFileToThirdQaComRespDto !=null){
          GenerateFileQaComReqDto generateFileQaComReqDto=new GenerateFileQaComReqDto();
  if(implementUploadFileToThirdQaComRespDto!=null){
      generateFileQaComReqDto.setLongTextFileId(implementUploadFileToThirdQaComRespDto.getThirtPartFileId());//SimpleFieldAssign//sourceId:2036985_1
    }

    /*D2生成单个文件长文本问答(公共)[10426]   */
    Assert.isNull(generateFileQaComReqDto.getLongTextFileId(),"D8执行单个文件长文本问答(公共)-D2生成单个文件长文本问答(公共)-长文本文件ID不能为空",false);
      generateFileQaComRespDto = fwCompIntelligentCommunicationClient.generateFileQaCom(generateFileQaComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;



           }

//步骤2: D2执行导向第三方智能问答(公共) - implementGuidedThirdPartyIntelligentQaCom
     ImplementGuidedThirdPartyIntelligentQaComRespDto implementGuidedThirdPartyIntelligentQaComRespDto = null;
    if(generateFileQaComRespDto !=null){
          ImplementGuidedThirdPartyIntelligentQaComReqDto implementGuidedThirdPartyIntelligentQaComReqDto=new ImplementGuidedThirdPartyIntelligentQaComReqDto();
  implementGuidedThirdPartyIntelligentQaComReqDto.setResultAspObjId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID//sourceId:2034170_1
implementGuidedThirdPartyIntelligentQaComReqDto.setBusModelVersion("LONG_TEXT_VERSION");//sourceId:2036981_1
if(generateFileQaComRespDto!= null&&  generateFileQaComRespDto.getGetListIntelligentAnswersList() !=null&& !CollectionUtil.isEmpty(generateFileQaComRespDto.getGetListIntelligentAnswersList())){
      implementGuidedThirdPartyIntelligentQaComReqDto.setGetListIntelligentAnswersList(generateFileQaComRespDto.getGetListIntelligentAnswersList().stream().map(item -> BeanUtil.toBean(item, GetListIntelligentAnswersDto.class)).collect(Collectors.toList()));//objList-to-objLists//sourceId:2034171_1
    }

    /*D2执行导向第三方智能问答(公共)[8103]   */
    Assert.isNull(implementGuidedThirdPartyIntelligentQaComReqDto.getResultAspObjId(),"D8执行单个文件长文本问答(公共)-D2执行导向第三方智能问答(公共)-开通对象ID不能为空",false);
Assert.isNull(implementGuidedThirdPartyIntelligentQaComReqDto.getBusModelVersion(),"D8执行单个文件长文本问答(公共)-D2执行导向第三方智能问答(公共)-业务模型版本不能为空",false);
      implementGuidedThirdPartyIntelligentQaComRespDto = fwCompIntelligentCommunicationClient.implementGuidedThirdPartyIntelligentQaCom(implementGuidedThirdPartyIntelligentQaComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


      implementGuidedThirdPartyIntelligentQaComRespDto_1 = implementGuidedThirdPartyIntelligentQaComRespDto;
           }

//步骤3: D2-执行markdown转文本(公共) - implementMarkdownTurnToTextCom
     ImplementMarkdownTurnToTextComRespDto implementMarkdownTurnToTextComRespDto = null;
    if(implementGuidedThirdPartyIntelligentQaComRespDto !=null){
          ImplementMarkdownTurnToTextComReqDto implementMarkdownTurnToTextComReqDto=new ImplementMarkdownTurnToTextComReqDto();
  if(implementGuidedThirdPartyIntelligentQaComRespDto!=null){
      implementMarkdownTurnToTextComReqDto.setMarkdownContent(implementGuidedThirdPartyIntelligentQaComRespDto.getContent());//SimpleFieldAssign//sourceId:2037011_1
    }

    /*D2-执行markdown转文本(公共)[7517]   */

      implementMarkdownTurnToTextComRespDto = fwCompInterfaceModeClient.implementMarkdownTurnToTextCom(implementMarkdownTurnToTextComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;



           }

//步骤4: D8修改资源文件(公共) - updateResourceFileCom
     UpdateResourceFileComRespDto updateResourceFileComRespDto = null;
    if(implementMarkdownTurnToTextComRespDto !=null){
          UpdateResourceFileComReqDto updateResourceFileComReqDto=new UpdateResourceFileComReqDto();
  if(reqDto!=null){
      updateResourceFileComReqDto.setResourceFileId(reqDto.getResourceFileId());//SimpleFieldAssign//sourceId:2034178_1
    }
if(implementMarkdownTurnToTextComRespDto!=null){
      updateResourceFileComReqDto.setResourceFileSummary(implementMarkdownTurnToTextComRespDto.getCustomText());//SimpleFieldAssign//sourceId:2034174_1
    }

    /*D8修改资源文件(公共)[10317]   */
    Assert.isNull(updateResourceFileComReqDto.getResourceFileId(),"D8执行单个文件长文本问答(公共)-D8修改资源文件(公共)-资源文件ID不能为空",false);
Assert.isNull(updateResourceFileComReqDto.getResourceFileSummary(),"D8执行单个文件长文本问答(公共)-D8修改资源文件(公共)-资源文件简介不能为空",false);
      updateResourceFileComRespDto = resourceFileService.updateResourceFileCom(updateResourceFileComReqDto)/*vcase invoke isSameApp*/;



           }

ImplementFileQaComRespDto retData = new ImplementFileQaComRespDto();
  if(implementGuidedThirdPartyIntelligentQaComRespDto_1!=null){
      retData.setContent(implementGuidedThirdPartyIntelligentQaComRespDto_1.getContent());//SimpleFieldAssign//sourceId:2034916_1
    }




return retData;
  }
  //
}
